function getDate(){
    const now = new Date();
    return  `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')} ${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`;
}
async function query(page,startTime,endTime,board_id,operations) {
    const url = "https://tianji.in.zhihu.com/api/v1/log/tickets?page=" + page + "&page_size=100&start_time=" + startTime + "&end_time=" + endTime + "&board_id=" + board_id + "&operations=" + operations;
    const data = (await (await fetch(url)).json()).data;
    tokens.push(...data.list.map(x => x.obj_token));
    if (!data.paging.is_end) {
        await query(page + 1,startTime,endTime,board_id,operations);
    }
}
async function queryToken(page,startTime,endTime,token) {
    const data = (await (await fetch("https://tianji.in.zhihu.com/api/v1/log/tickets?page=1&page_size=100&obj_token=" + token)).json()).data;
    reviewer_emails.push(...data.list.map(x => x.reviewer_email));
    if (!data.paging.is_end) {
        await queryToken(page + 1,startTime,endTime);
    }
}
async function filterA2SameValue(arr) {
    for(let i=0; i<arr.length; i++){
        const data = (await (await fetch("https://tianji.in.zhihu.com/api/v1/log/tickets?page=1&page_size=100&obj_token=" + arr[i])).json()).data.list.filter(x=>x.action===4);
        if(data.length>=2){
            const filteredList = data.map(x=>x.ticket_result.operations).flat().filter(item => item !== undefined);
            if(filteredList.map(x=>x.params.mark_type).every((value, index, arr) => value === arr[0])){
                console.info("%c"+(i+1)+"/"+arr.length+":重复，去除",'background-color: green; padding: 6px 12px; border-radius: 2px; font-size: 14px; color: #fff; text-transform: uppercase; font-weight: 600;');
            }else{
                let info=data.filter(x=>x.reviewer_email==="gouxiaojuan@zhihu.com").map(x=>x.correction_recordation_info)
                if(info.length!==0&&info[0].can_correct){
                    tokensInA2.push(arr[i])
                    console.info("%c"+(i+1)+"/"+arr.length+":没有重复，有修正的机会，"+arr[i]+"放入正常集合,当前有"+tokensInA2.length,'background-color: red; padding: 6px 12px; border-radius: 2px; font-size: 14px; color: #fff; text-transform: uppercase; font-weight: 600;');
                }else{
                    console.info("%c"+(i+1)+"/"+arr.length+":没有重复，但是不能再修正，忽略",'background-color: green; padding: 6px 12px; border-radius: 2px; font-size: 14px; color: #fff; text-transform: uppercase; font-weight: 600;');
                }
            }
        }else{
            tokensInA2.push(arr[i])
            console.info("%c"+(i+1)+"/"+arr.length+":没有重复，"+arr[i]+" 放入正常集合,当前有"+tokensInA2.length, 'background-color: red; padding: 6px 12px; border-radius: 2px; font-size: 14px; color: #fff; text-transform: uppercase; font-weight: 600;');
        }
    }
    console.log("循环查询完毕:"+JSON.stringify(Array.from(new Set(tokensInA2))))
}
let exit = false;
const tokens = [];
let reviewer_emails = [];
let result_tokens = [];
let tokensInA2=[]
while(!exit){
    console.log("第一步：请输入数字：\n1.查A1\n2.查A2\n0.退出")
    const a1OrA2 = prompt("第一步：请输入数字：\n1.查A1\n2.查A2\n0.退出");
    console.log("您输入的是"+a1OrA2)
    if(a1OrA2==="0"){
        exit=true
    }else{
        console.log("第二步：请输入板块：\n1.内容分层-复审图文\n2.重新选择")
        const board_res = prompt("第二步：请输入板块：\n1.内容分层-复审图文\n2.重新选择");
        console.log("您输入的是"+board_res)
        if(board_res==="2"){
            continue
        }
        const board_id=board_res==="1"?3630014:""
        if(board_id==="")continue
        const operations=a1OrA2==="1"?"327":"329"
        console.log("第三步：请输入开始时间")
        let startTime = prompt("第三步：请输入开始时间(如2000-10-18)：", getDate());
        console.log("您输入的是"+startTime)
        startTime= Math.floor(new Date(startTime).getTime() / 1000)
        let endTime = prompt("第四步：请输入结束时间(如2000-10-18)：",getDate());
        console.log("您输入的是"+endTime)
        endTime= Math.floor(new Date(endTime).getTime() / 1000)
        const operatorName = prompt("第五步：根据内容token要查询的操作人：","gouxiaojuan@zhihu.com");
        console.log("您输入的是"+operatorName)
        console.log("正在查询结果,请傻等");
        await query(1,startTime,endTime,board_id,operations)
        console.log("所有要查询的token（"+tokens.length+"个）："+tokens);
        console.log("开始查询token对应的操作人");
        for (let i = 0; i < tokens.length; i++) {
            console.log(`第${i}/${tokens.length}次，查询token：${tokens[i]}`)
            reviewer_emails=[]
            await queryToken(1,startTime,endTime,tokens[i])
            const hasMe = reviewer_emails.includes(operatorName);
            if(hasMe){
                console.info(
                    `%c 发现${operatorName}存在,请记住它的token：${tokens[i]}`,
                    'background-color: red; padding: 6px 12px; border-radius: 2px; font-size: 14px; color: #fff; text-transform: uppercase; font-weight: 600;'
                );
                result_tokens.push(tokens[i])
            }
        }
        console.log("循环查询完毕:"+JSON.stringify(result_tokens))
        if(a1OrA2==="2"){
            console.log("开始过滤相同操作对象")
            await filterA2SameValue(result_tokens)
        }
    }
}